﻿'*******************************************************************************************
'* Copyright Brügmann Software GmbH, Papenburg
'* Author: Björn Kremer
'* Contact: codeplex<at>patorg.de
'* 
'* VB.CMIS is a VB.NET implementation of the Content Management Interoperability Services (CMIS) standard
'*
'* This file is part of VB.CMIS.
'* 
'* VB.CMIS is free software: you can redistribute it and/or modify
'* it under the terms of the GNU Lesser General Public License as published by
'* the Free Software Foundation, either version 3 of the License, or
'* (at your option) any later version.
'* 
'* VB.CMIS is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'* GNU Lesser General Public License for more details.
'* 
'* You should have received a copy of the GNU Lesser General Public License
'* along with VB.CMIS. If not, see <http://www.gnu.org/licenses/>.
'*******************************************************************************************
Imports System.Runtime.Serialization
Imports System.Xml.Serialization

Namespace ServiceDocument
   <XmlRoot("aclCapability", Namespace:=CmisNamespaceConstants.Cmis)> _
   Public Class AclCapability
      Implements IXmlSerializable

      Public Property Propagation() As AclPropagation

      Public Enum AclPropagation

         <EnumMember(Value:="repositorydetermined")> _
         RepositoryDetermined

         <EnumMember(Value:="objectonly")> _
         ObjectOnly

         <EnumMember(Value:="propagate")> _
         Propagate
      End Enum

      Public Property Permissions() As PermissionDefinition()

      Public Property Mapping() As PermissionMapping()

      Public Property SupportedPermissions As SupportedPermissionsEnum

      Public Enum SupportedPermissionsEnum
         <EnumMember(Value:="basic")> _
         Basic
         <EnumMember(Value:="repository")> _
         Repository
         <EnumMember(Value:="both")> _
         Both
      End Enum

      Public Function GetSchema() As System.Xml.Schema.XmlSchema Implements System.Xml.Serialization.IXmlSerializable.GetSchema
         Return Nothing
      End Function

      Public Sub ReadXml(reader As System.Xml.XmlReader) Implements System.Xml.Serialization.IXmlSerializable.ReadXml

      End Sub

      Public Sub WriteXml(writer As System.Xml.XmlWriter) Implements System.Xml.Serialization.IXmlSerializable.WriteXml
         writer.WriteElementString("supportedPermissions", CmisNamespaceConstants.Cmis, Common.GetDataMemberValueFromEnum(SupportedPermissions, GetType(SupportedPermissionsEnum)))
         writer.WriteElementString("propagation", CmisNamespaceConstants.Cmis, Common.GetDataMemberValueFromEnum(Propagation, GetType(AclPropagation)))

         If Permissions IsNot Nothing Then
            For Each p As PermissionDefinition In Permissions
               Dim serializer As New XmlSerializer(p.GetType)
               serializer.Serialize(writer, p)
            Next
         End If
         If Mapping IsNot Nothing Then
            For Each m As PermissionMapping In Mapping
               Dim serializer As New XmlSerializer(m.GetType)
               serializer.Serialize(writer, m)
            Next
         End If
      End Sub
   End Class

End Namespace